Add a GtkFontButton:modal property
authorMatthias Clasen <mclasen@redhat.com>
Mon, 13 Apr 2020 04:28:34 +0000 (00:28 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 13 Apr 2020 04:28:34 +0000 (00:28 -0400)
Nowadays, dialogs are expected to be attached, typically,
and that only happens when they are marked as modal.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkfontbutton.c
gtk/gtkfontbutton.h

index 41bd9b6d5248e18e8d89d601f35f42dced75a567..cf6e42c3c491f420a47aeb1c63e3ec57f2eb7261 100644 (file)
@@ -1273,6 +1273,8 @@ gtk_font_button_set_use_size
 gtk_font_button_get_use_size
 gtk_font_button_set_title
 gtk_font_button_get_title
+gtk_font_button_set_modal
+gtk_font_button_get_modal
 <SUBSECTION Standard>
 GTK_FONT_BUTTON
 GTK_IS_FONT_BUTTON
index 1cad2f6c5937360215e55c458ddb2e869dc825da..ce4eba6443d58ba9e73a9666ed5370da2abf10b0 100644 (file)
@@ -85,6 +85,7 @@ typedef struct
   guint         use_font : 1;
   guint         use_size : 1;
   guint         show_preview_entry : 1;
+  guint         modal    : 1;
 
   GtkWidget     *button;
   GtkWidget     *font_dialog;
@@ -119,6 +120,7 @@ enum
 {
   PROP_0,
   PROP_TITLE,
+  PROP_MODAL,
   PROP_USE_FONT,
   PROP_USE_SIZE
 };
@@ -532,6 +534,14 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
                                                          FALSE,
                                                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
 
+  g_object_class_install_property (gobject_class,
+                                   PROP_MODAL,
+                                   g_param_spec_boolean ("modal",
+                                                         P_("Modal"),
+                                                         P_("Whether the dialog is modal"),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+
   /**
    * GtkFontButton::font-set:
    * @widget: the object which received the signal.
@@ -580,6 +590,7 @@ gtk_font_button_init (GtkFontButton *font_button)
   gtk_widget_set_parent (priv->button, GTK_WIDGET (font_button));
 
   /* Initialize fields */
+  priv->modal = TRUE;
   priv->use_font = FALSE;
   priv->use_size = FALSE;
   priv->show_preview_entry = TRUE;
@@ -640,6 +651,9 @@ gtk_font_button_set_property (GObject      *object,
     case PROP_TITLE:
       gtk_font_button_set_title (font_button, g_value_get_string (value));
       break;
+    case PROP_MODAL:
+      gtk_font_button_set_modal (font_button, g_value_get_boolean (value));
+      break;
     case GTK_FONT_CHOOSER_PROP_FONT_DESC:
       gtk_font_button_take_font_desc (font_button, g_value_dup_boxed (value));
       break;
@@ -684,6 +698,9 @@ gtk_font_button_get_property (GObject    *object,
     case PROP_TITLE:
       g_value_set_string (value, gtk_font_button_get_title (font_button));
       break;
+    case PROP_MODAL:
+      g_value_set_boolean (value, gtk_font_button_get_modal (font_button));
+      break;
     case GTK_FONT_CHOOSER_PROP_FONT_DESC:
       g_value_set_boxed (value, gtk_font_button_get_font_desc (font_button));
       break;
@@ -782,6 +799,50 @@ gtk_font_button_get_title (GtkFontButton *font_button)
   return priv->title;
 } 
 
+/**
+ * gtk_font_button_set_modal:
+ * @font_button: a #GtkFontButton
+ * @modal: %TRUE to make the dialog modal
+ *
+ * Sets whether the dialog should be modal.
+ */
+void
+gtk_font_button_set_modal (GtkFontButton *font_button,
+                           gboolean       modal)
+{
+  GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
+
+  g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
+
+  if (priv->modal == modal)
+    return;
+
+  priv->modal = modal;
+
+  if (priv->font_dialog)
+    gtk_window_set_modal (GTK_WINDOW (priv->font_dialog), priv->modal);
+
+  g_object_notify (G_OBJECT (font_button), "modal");
+}
+
+/**
+ * gtk_font_button_get_modal:
+ * @font_button: a #GtkFontButton
+ *
+ * Gets whether the dialog is modal.
+ *
+ * Returns: %TRUE if the dialog is modal
+ */
+gboolean
+gtk_font_button_get_modal (GtkFontButton *font_button)
+{
+  GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
+
+  g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
+
+  return priv->modal;
+}
+
 /**
  * gtk_font_button_get_use_font:
  * @font_button: a #GtkFontButton
@@ -907,6 +968,7 @@ gtk_font_button_clicked (GtkButton *button,
 
       priv->font_dialog = gtk_font_chooser_dialog_new (priv->title, NULL);
       gtk_window_set_hide_on_close (GTK_WINDOW (priv->font_dialog), TRUE);
+      gtk_window_set_modal (GTK_WINDOW (priv->font_dialog), priv->modal);
 
       font_dialog = GTK_FONT_CHOOSER (priv->font_dialog);
 
@@ -940,8 +1002,8 @@ gtk_font_button_clicked (GtkButton *button,
           if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog)))
             gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent));
 
-          gtk_window_set_modal (GTK_WINDOW (font_dialog),
-                                gtk_window_get_modal (GTK_WINDOW (parent)));
+          if (gtk_window_get_modal (GTK_WINDOW (parent)))
+            gtk_window_set_modal (GTK_WINDOW (font_dialog), TRUE);
         }
 
       g_signal_connect (font_dialog, "notify",
index 659cd3288fb37b37fbc3d9b8bfa919af1bbe3b97..8cb7bf008d41069900169a1df5bf788f44d69a5c 100644 (file)
@@ -54,6 +54,11 @@ GDK_AVAILABLE_IN_ALL
 void                  gtk_font_button_set_title      (GtkFontButton *font_button,
                                                       const gchar   *title);
 GDK_AVAILABLE_IN_ALL
+gboolean              gtk_font_button_get_modal      (GtkFontButton *font_button);
+GDK_AVAILABLE_IN_ALL
+void                  gtk_font_button_set_modal      (GtkFontButton *font_button,
+                                                      gboolean       modal);
+GDK_AVAILABLE_IN_ALL
 gboolean              gtk_font_button_get_use_font   (GtkFontButton *font_button);
 GDK_AVAILABLE_IN_ALL
 void                  gtk_font_button_set_use_font   (GtkFontButton *font_button,